package com.keyancompany.zhongbaopingtai;

import android.app.Application;
import android.graphics.Bitmap;

import com.keyancompany.zhongbaopingtai.utils.T;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
import com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
import com.nostra13.universalimageloader.utils.L;

import java.io.File;

/**
 * Created by firefox on 2016/6/1.
 */
public class ZBApplication extends Application {


    private static ZBApplication instance;

    public static ZBApplication getInstance() {
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
//        L.isDebug = true;
        T.isShow = true;
        DisplayImageOptions options = new DisplayImageOptions.Builder()

                .showImageForEmptyUri(R.drawable.ic_picture_loadfailed)
                .showImageOnLoading(R.drawable.ic_picture_loadfailed)
                .showImageOnFail(R.drawable.ic_picture_loadfailed)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .imageScaleType(ImageScaleType.IN_SAMPLE_INT).build();
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
                this)
                .memoryCacheExtraOptions(480, 800)
                .threadPoolSize(3)
                .threadPriority(Thread.NORM_PRIORITY - 2)
                .denyCacheImageMultipleSizesInMemory()
                .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
                .memoryCacheSize(2 * 1024 * 1024)
                .diskCache(new UnlimitedDiscCache(new File(Constants.CACHE_PATH))) // defa
                .tasksProcessingOrder(QueueProcessingType.LIFO)
                .defaultDisplayImageOptions(options)
                .imageDownloader(
                        new BaseImageDownloader(this, 5 * 1000, 30 * 1000))
//                .writeDebugLogs()

                .build();
        L.disableLogging();

        ImageLoader.getInstance().init(config);

    }


}
